package m.jclecai.com.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import m.jclecai.com.R;

import java.util.List;
import java.util.Map;


public class PassAdapter extends BaseAdapter {

	private Context ctxt;
	private String[] list;
	private String[] types;
	private List<Integer> id;
	private Map<String, String> map;

	public PassAdapter(Context ctxt, String[] list, String[] types,
			List<Integer> type, Map<String, String> map) {
		this.ctxt = ctxt;
		this.list = list;
		this.types = types;
		this.id = type;
		this.map = map;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return id.get(0) - 1;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(ctxt).inflate(R.layout.fragment_hemai_popuwindow_item, null);
			viewHolder.txt_hemai_popuwindow = (TextView) convertView
					.findViewById(R.id.txt_hemai_popuwindow);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		String name = list[position];
		String type = types[position];
		if (map.containsKey(name)) {
			viewHolder.txt_hemai_popuwindow
					.setBackgroundResource(R.drawable.hemai_popuwindow_txt_bg_press);
		} else {
			viewHolder.txt_hemai_popuwindow
					.setBackgroundResource(R.drawable.hemai_popuwindow_txt_bg);
		}
		viewHolder.txt_hemai_popuwindow.setText(name);
		viewHolder.txt_hemai_popuwindow.setTag(type);
		return convertView;
	}

	class ViewHolder {
		public TextView txt_hemai_popuwindow;
	}

}